package day08.test2;

class PrintString implements Runnable {
    private boolean isContinuePrint = true;

    public boolean isContinuePrint() {
        return this.isContinuePrint;
    }

    public void setContinuePrint(boolean isContinuePrint) {
        this.isContinuePrint = isContinuePrint;

    }


    @Override
    public void run() {
        try {
            while (isContinuePrint) {
                System.out.println("run printStringMethod threadName="
                        + Thread.currentThread().getName());
                Thread.sleep(1000);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}


class RunPrintString {
    public static void main(String[] args) throws Exception {
        PrintString printStringService = new PrintString();
        Thread thread = new Thread(printStringService);
        thread.start();
        Thread.sleep(1000 * 3);
        System.out.println("我要停止它！stopThread=" + Thread.currentThread().getName());
        Thread.sleep(2000);
        printStringService.setContinuePrint(false);
    }
}